package com.woniuxy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.page.PageParams;
import com.woniuxy.entity.Books;
import com.woniuxy.mapper.BooksMapper;
import com.woniuxy.service.BooksService;
import com.woniuxy.util.PageParam;
import com.woniuxy.util.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author HP
 * @version 1.0
 * @project
 * @description
 * @date 2024/4/9 19:22:47
 */
@Service
public class BooksServiceImpl implements BooksService {

    @Autowired
    private BooksMapper booksMapper;

    @Override
    public ResponseData<?> addBooks(Books books) {

        booksMapper.addBooks(books);
        return new ResponseData<>().ok();
    }

    @Override
    public ResponseData<?> queryBooks(PageParam<Books> pageParam) {
        PageHelper.startPage(pageParam.getPageNum(), pageParam.getPageSize());
        List<Books> books = booksMapper.queryBooks(pageParam.getParam());
        PageInfo pageInfo = new PageInfo(books);

        return new ResponseData<>().ok(pageInfo);
    }
}
